/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BarPanel.java
 *
 * Created on Dec 14, 2011, 10:34:43 PM
 */
package com.bao.panel;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Paint;
import java.awt.PaintContext;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.ColorModel;
import java.text.MessageFormat;
import java.util.ArrayList;
import javax.swing.SwingUtilities;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author Bao
 */
public class BarPanel extends javax.swing.JPanel {
ChartPanel chartPanel;


    /** Creates new form BarPanel */
    public BarPanel() {
        initComponents();
         final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

            dataset.addValue(1.0, "First", "cat1");
            dataset.addValue(2.0, "First", "cat2");
            dataset.addValue(3.0, "First", "cat3");
            dataset.addValue(4.0, "First", "cat4");
            dataset.addValue(5.0, "First", "cat5");
          JFreeChart chart = ChartFactory.createBarChart("ABC", 
                  "cat", "value", dataset, PlotOrientation.VERTICAL, true, true, true);
           CategoryPlot plot = chart.getCategoryPlot();
           Paint redP = Color.red;
           Paint greenP = Color.green;
           
           
           //plot.setRenderer(new BarRender1(redP, greenP));
           //Set tooltip for each bar - Begin
           BarRenderer barRender = new BarRender1(redP, greenP);
           StandardCategoryToolTipGenerator generator = new StandardCategoryToolTipGenerator(){

            @Override
            public String generateToolTip(CategoryDataset dataset, int row, int column) {
                if (dataset == null) {
                    throw new IllegalArgumentException("Null 'dataset' argument.");
                }
                String result = null;
                Object[] items = createItemArray(dataset, row, column);
                result = MessageFormat.format("{2}", items);
                return result;
            }};
           barRender.setSeriesToolTipGenerator(0, generator);           
           plot.setRenderer(barRender);
           //Set tooltip for each bar - End
           
            chartPanel = new ChartPanel1(chart);
            chartPanel.setPopupMenu(null);
            //Mouse listener
            chartPanel.addMouseListener(new MouseListener() {
                int a =2;
            @Override
            public void mouseClicked(MouseEvent e) {
//                if (SwingUtilities.isRightMouseButton(e)){
//                    int ab=2;
//                }
            }

            @Override
            public void mousePressed(MouseEvent e) {
                //throw new UnsupportedOperationException("Not supported yet.");
            }

            @Override
            public void mouseReleased(MouseEvent e) {
//                if (SwingUtilities.isRightMouseButton(e)){
//                    int ab=2;
//                }
                  if (e.isPopupTrigger()) {
                      if (this.popup != null) {
                          //#?displayPopupMenu(e.getX(), e.getY());
                          restoreZoomPoint();      
                      }
              }
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                //throw new UnsupportedOperationException("Not supported yet.");
            }

            @Override
            public void mouseExited(MouseEvent e) {
                //throw new UnsupportedOperationException("Not supported yet.");
            }
        });
            
            Dimension d = new Dimension(200,100);
            chartPanel.setSize(d);
            chartPanel.setPreferredSize(d);
            BorderLayout layout = new BorderLayout();
            this.setLayout(layout);
            this.add(chartPanel,BorderLayout.CENTER);  
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
